Landsat Spectral Clustering ¶
Right click to download this notebook from GitHub.
The image loaded here is a cropped portion of a LANDSAT image of Walker Lake .
In addition to
dask-ml
, we'll use
rasterio
to read the data and
matplotlib
to plot the figures.
I'm just working on my laptop, so we could use either the threaded or distributed scheduler, but here I'll use the distributed scheduler for the diagnostics.
In [1]:
import rasterio
import numpy as np
import xarray as xr
import holoviews as hv
from holoviews.operation.datashader import regrid
import cartopy.crs as ccrs
import dask.array as da
from dask_ml.cluster import SpectralClustering
from dask.distributed import Client
hv.extension('bokeh')
In [2]:
client = Client(processes=False)
client
Out[2]:
In [3]:
import intake
cat = intake.open_catalog('../catalog.yml')
list(cat)
Out[3]:
In [4]:
l5_img = cat.l5.read_chunked()
l5_img
Out[4]:
In [5]:
crs=ccrs.epsg(32611)
In [6]:
x_center, y_center = crs.transform_point(-118.7081, 38.6942, ccrs.PlateCarree())
buffer = 1.7e4
xmin = x_center - buffer
xmax = x_center + buffer
ymin = y_center - buffer
ymax = y_center + buffer
ROI = l5_img.sel(x=slice(xmin, xmax), y=slice(ymax, ymin))
ROI = ROI.where(ROI > ROI.nodatavals[0])
In [7]:
bands = ROI.astype(float)
bands = (bands - bands.mean()) / bands.std()
bands
Out[7]:
In [8]:
%%opts Image [invert_yaxis=True width=250 height=250 tools=['hover']] (cmap='viridis')
hv.Layout([regrid(hv.Image(band, kdims=['x', 'y'])) for band in bands[:3]])
Out[8]:
In [9]:
%%opts Image [invert_yaxis=True width=250 height=250 tools=['hover']] (cmap='viridis')
hv.Layout([regrid(hv.Image(band, kdims=['x', 'y'])) for band in bands[3:]])
Out[9]: